import React from "react"
import { Card } from 'antd';
import Advanced0201 from "./advanced0201"
const DJS = {
    count: 0,
    subscribe(callback) {
        setInterval(() => {
            this.count++
            console.log()
            return callback(this.count)
        }, 1000)
    }
}


class Advanced02 extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            count: 0
        }

    }
    componentDidMount() {
        DJS.subscribe(currentCount => {
            this.setState({
                count: currentCount
            })
        })
    }
    componentWillUnmount = () => {
        //卸载了 就不 进行 setState
        this.setState = (state, callback) => {
            return;
        };
    }
    render() {
        console.log("父组建重新渲染")
        return (
            <Card title="切换页面时 要停掉所有异步请求" bordered={false}>
                <p>父组建{this.state.count}</p>
                <Advanced0201 num={this.state.count} />
            </Card>
        )
    }
}
export default Advanced02